import * as Global from '../TS/Global';
import * as NavBar from './LeftNavBar';

//网口配置
export interface MsgCfg_net {
    NetName: string;
    IPMethod?: string;
    Ip?: string;
    Mask?: string;
    Gateway?: string;
    IsSetMac?: boolean;
    MAC?: string;

}
//串口配置
export interface Serial_cfg {

    SPath?: string; //端口名称
    IsOn?: boolean; //是否启用
    Baudrate?: string; //波特率
    Checkbit?: string; //校验位
    Databit?: string; //数据位
    Stopbit?: string; //停止位
    MaxLength?: string; //包的最大长度
    Interval?: string; //包之间的最小时间间隔
    SyncBaudrate?: boolean; //同步波特率 RFC2217
    ISHeartbeat?: boolean; //是否启用心跳包
    Heartbeat_Hex?: string; //心跳包字节
    Heartbeat_Interval?: string; //心跳包间隔
    Is_FullDuplex?: false;
    ServiceList?: Service_cfg[]; //服务列表
}
//服务配置
export interface Service_cfg {

    IsOn?: boolean;
    ServiceType?: string;
    NetNum?: string;
    RemoteIP?: string;
    IsspecifyPort?: string;
    RemotePort?: string;
    LocalPort?: string; //本地端口
    ISHeartbeat?: boolean; //是否启用心跳包
    Heartbeat_Hex?: string; //心跳包字节
    Heartbeat_Interval?: string; //心跳包间隔

}
export interface MsgCfg {
    DeviceName: string;
    User: string;
    PWD: string;
    DNS1?: string;
    DNS2?: string;
    IsSetDNS?: boolean,
    Net_cfg: MsgCfg_net[];
    Serial_cfg?: Serial_cfg[];
}

let testjson = {
    cmd: "TheCfg",
    DeviceName: "测试设备",
    User: 'admin',
    PWD: 'admin',
    IsSetDNS: false,
    DNS1: "223.51.51.51",
    DNS2: "114.114.114.114",
    Net_cfg: [
        {
            NetName: "eth2",
            Ip: "192.168.3.25   0",
            Mask: "255.255.255.0",
            Gateway: "192.168.3.1",
            MAC: "",

        }, {
            NetName: "eth3",
            Ip: "192.168.4.200",
            Mask: "255.255.255.0",
            Gateway: "192.168.3.1",
            MAC: "",

        }
    ],
    Serial_cfg: [
        {
            IsOn: true,
            SPath: '/dev/ttySAC1',
            Baudrate: "115200",
            Checkbit: "NONE",
            Databit: "8",
            Stopbit: "1",
            MaxLength: "1024", //包的最大长度
            Interval: "20", //包之间的最小时间间隔
            SyncBaudrate: false, //同步波特率 RFC2217
            ISHeartbeat: false, //是否启用心跳包
            Heartbeat_Hex: "FF FF", //心跳包字节
            Heartbeat_Interval: "50000", //心跳包间隔
            Is_FullDuplex: false,


            ServiceList: [

                {
                    IsOn: true,
                    ServiceType: 'UDP',
                    NetNum: "1",
                    RemoteIP: '192.168.3.71',
                    IsspecifyPort: 'true',
                    RemotePort: "9999",
                    LocalPort: "5999",

                    ISHeartbeat: false,//是否启用心跳包
                    Heartbeat_Hex: "FF FF", //心跳包字节
                    Heartbeat_Interval: "5000" //心跳包间隔
                }
            ]
        }, {
            IsOn: false,
            SPath: '/dev/ttySAC2'

        }, {
            IsOn: false,
            SPath: '/dev/ttySAC4'
        }, {
            IsOn: false,
            SPath: '/dev/ttySAC5'
        }, {
            IsOn: false,
            SPath: '/dev/ttyS0'
        }, {
            IsOn: false,
            SPath: '/dev/ttyS1'
        }, {
            IsOn: false,
            SPath: '/dev/ttyS2'
        }, {
            IsOn: false,
            SPath: '/dev/ttyS3'
        }

    ]
};
export var mycfg: MsgCfg = testjson as MsgCfg;
export let tc: number = 0;
export let MenuListtest: NavBar.MenuNode[] = [];

export function InitMemu(): void {
    MenuListtest = [];
    let menu1: NavBar.MenuNode = {
        NodeName: Global.GetLocal("系统配置"),
        NodeChildren: [
            {
                NodeName: Global.GetLocal("设备信息设置")
            }, {
                NodeName: Global.GetLocal("网口设置")
            }, {
                NodeName: Global.GetLocal("SH命令")
            },
            {
                NodeName: Global.GetLocal("配置处理")
            },
            {
                NodeName: Global.GetLocal("系统升级")
            }, {
                NodeName: Global.GetLocal("重启")
            }
        ]

    };
    MenuListtest.push(menu1);
    let menu2: NavBar.MenuNode = {
        NodeName: Global.GetLocal("串口配置"),
        NodeChildren: []
    };

    for (let i = 1; i <= mycfg.Serial_cfg.length; i++) {
        menu2
            .NodeChildren
            .push({
                NodeName: Global.GetLocal("串口号") + " " + i
            });
    }

    MenuListtest.push(menu2);
    let menu3: NavBar.MenuNode = {
        NodeName: Global.GetLocal("附加工具"),
        NodeChildren: [
            {
                NodeName: Global.GetLocal("串口批量配置")
            }, {
                NodeName: Global.GetLocal("设备状态")
            }
        ]

    };
    //MenuListtest.push(menu3);
}